/*
 * chtbl.h
 *
 *  Created on: Jun 10, 2012
 *      Author: Rui Carlos Lorenzetti da Silva
 */

#ifndef CHTBL_H
#define CHTBL_H

#include <stdlib.h>

#include "list.h"

/**
 * Definição da estrutura de Chained HashTable
 */

typedef struct CHTbl_ {

int                buckets;

int                (*h)(const void *key);
int                (*match)(const void *key1, const void *key2);
void               (*destroy)(void *data);

int                size;
List               *table;

} CHTbl;

/**
 * Interface publica
 */

int chtbl_init(CHTbl *htbl, int buckets, int (*h)(const void *key), int
   (*match)(const void *key1, const void *key2), void (*destroy)(void *data));

void chtbl_destroy(CHTbl *htbl);

int chtbl_insert(CHTbl *htbl, const void *data);

int chtbl_remove(CHTbl *htbl, void **data);

List * chtbl_lookup(const CHTbl *htbl, void *data,void (*destroy)(void *data));

int chtbl_lookup_int(const CHTbl *htbl, void *data);

#define chtbl_size(htbl) ((htbl)->size)

#endif
